package br.odb.utils.math;

import br.odb.utils.Utils;

public class Vec2 {

	public float x;
	public float y;
	public int space;

	// ------------------------------------------------------------------------------------------------------------
	public Vec2() {
		x = 0;
		y = 0;
	}
	
	// ------------------------------------------------------------------------------------------------------------
	public Vec2(int i, int i0) {
		
		x = i;
		y = i0;
	}

	// ------------------------------------------------------------------------------------------------------------
	public Vec2( float d, float d0) {
		x = d;
		y = d0;
	}
	// ------------------------------------------------------------------------------------------------------------
	public Vec2 add( Vec2 v ) {
		
		return new Vec2( x + v.x, y + v.y );
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}
	
	
	public String toString() {

		return "Vec2( " + x + ", " + y + ")"; 
	}
	
	
	public int hashCode() {
		
		return toString().hashCode();
	}

	public boolean equals( Vec2 v ) {
		
		if ( v == null )
			return false;
		
		return ( Utils.eqFloat( x, v.x ) && Utils.eqFloat( y, v.y ) );
	}

	
	
	public boolean equals(Object obj) {
		
		return equals( ( Vec2 ) obj ); 
	}

	public Vec2 sub(Vec2 initialPosition) {		
		return new Vec2( x - initialPosition.x, y - initialPosition.y );
	}
	
	public void invalidate() {
		x = Float.NaN;
		y = Float.NaN;
	}

	public boolean isValid() {
		return !Float.isNaN( x ) && !Float.isNaN( y ) && !Float.isInfinite( x ) && !Float.isInfinite( y );
	}

	public void set( Vec2 vec ) {
		this.x = vec.x;
		this.y = vec.y;
		this.space = vec.space;		
	}

	public void set( float x, float y ) {
		
		this.x = x;
		this.y = y;
	}
}